package com.tinyseed.emcp.api.basicdata.repository;

import com.tinyseed.emcp.api.basicdata.domain.MonitorRstData;
import com.tinyseed.emcp.api.basicdata.model.MonitorRstDataOutputDTO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;

/***
 * @ClassName: MonitorRstDataDataSource2Repository
 * @Description: TODO
 * @Auther: Harlan.Xiong
 * @Date: 2019-12-30 0:54
 * @version : V1.0
 */
public interface MonitorRstDataRepository extends JpaRepository<MonitorRstData, Long> {

    @Query(value = "select data_time as dataTime,pkw as pkw  from tb_monitor_rst_data m where switch_sn = :switchSn and m.device_sn = :deviceSn and to_char(m.data_time,'yyyy-mm-dd') = :dateTime limit 350 ", nativeQuery = true)
    List<MonitorRstDataOutputDTO> findAllBySwitchSnAndDeviceSnAndDataTime(@Param("switchSn") String switchSn, @Param("deviceSn") String deviceSn, @Param("dateTime") String dateTime);


    @Query(value = "select data_time as dataTime,pkw as pkw  from tb_monitor_rst_data m where switch_sn = :switchSn and m.device_sn = :deviceSn and  m.data_time<= :endTime and m.data_time>= :startTime limit 350 ", nativeQuery = true)
    List<MonitorRstDataOutputDTO> findAllBySwitchSnAndDeviceSnAndBetweenDataTime(@Param("switchSn") String switchSn, @Param("deviceSn") String deviceSn, @Param("startTime") Date startTime,@Param("endTime") Date endTime);

}
